Skip to content

Fix revenue dashboard: DB connection, tenant isolation, timezone, cent rounding, logout - #243

Open
sajaa45 wants to merge 8 commits into
Base360-AI:mainfrom
sajaa45:main
Open

sajaa45 wants to merge 8 commits into
Base360-AI:mainfrom
sajaa45:main

Conversation

@sajaa45

@sajaa45 sajaa45 commented Nov 17, 2026

Copy link
Copy Markdown

Summary

Fixes the three reported issues and one extra bug I found. Each fix is a separate commit.

Fixes

  1. Database never connected: the connection settings were wrong, and an error
    handler hid the failure by showing fake numbers. Fixed the connection and removed
    the fake data. Sunset's prop-001 now shows 2,250.00 instead of 1,000.00.

  2. Companies seeing each other's data: the cache was keyed by property ID only,
    and both companies have a prop-001. The cache key now includes the company. The
    company now comes only from the login token, and each company sees only its own
    properties.

  3. Wrong March totals (timezone): a booking on 29 Feb at 23:30 UTC is already
    1 March in Paris. Monthly revenue now uses each property's own timezone.

  4. Totals off by a cent: money was converted to float and rounded twice. It now
    stays exact (Decimal), is rounded once, and is sent as text.

  5. Logged out on refresh: a storage cleanup deleted the login token. The token is
    now always kept.

Testing

Tested as both clients: every total matches the database, each company sees only its
own properties, another company's property returns 404, and users stay logged in
after refreshing.

sajaa45 added 8 commits November 17, 2026 14:30
The pool passed QueuePool to an async engine and built its URL from
settings fields that do not exist, so initialization always failed. Every revenue request
then silently fell back to hardcoded mock totals keyed only by property
id: Sunset's prop-001 showed 1000.00 instead of 2250.00, and tenants
sharing a property id saw the same numbers.

Use the default async pool with settings.database_url, share one pool
instead of creating one per request, and let DB errors surface instead
of returning fake data.
Property ids are only unique per tenant (prop-001 exists for both
Sunset and Ocean), but the cache key was revenue:{property_id}. Whoever
loaded a property first had their totals served to the other tenant
for 5 minutes.
Amounts are stored with 3 decimals. The API converted the Decimal sum
to float and the frontend re-rounded it with Math.round, so totals
could drift by a cent. Round once on the server with ROUND_HALF_UP,
send the total as a decimal string, and format it without float math.

Also removes the hardcoded "+12%" trend badge, which was not based on
any data.
- The backend fell back to a "default_tenant" when the user had none;
  now it returns 403.
- The frontend sent an X-Simulated-Tenant header and hardcoded the
  property list (including other tenants' properties). Properties now
  come from GET /dashboard/properties, scoped to the user's tenant.
- Requesting another tenant's property returns 404 instead of 0.00.
- Ignore stale responses when switching properties quickly.
Any user not in the hardcoded email list was assigned tenant-a and
could see Sunset's revenue. Read tenant_id from the verified token
(app_metadata or root claim; never user-editable user_metadata), then
the known demo users, and otherwise return no tenant.
calculate_monthly_revenue was a stub returning 0, and its query used
UTC month boundaries: a booking at 2024-02-29 23:30 UTC in Paris
(already March 1 locally) would land in February, giving Sunset
1000.00 for March on Beach House Alpha instead of 2250.00.

Convert each check-in with check_in_date AT TIME ZONE p.timezone before
comparing it with the month boundaries, and scope the query by tenant.
The storage health check treated plain-string values (version marker,
language, ...) as corruption and cleared localStorage, auth token
included, which could log the user out. Skip non-JSON values and
always preserve the auth token.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant